package com.jvyou.singleton.hungry;

/**
 * @author 橘柚
 * @version 1.0-SNAPSHOT
 * @Date 2024/7/29 16:07
 * @Description 静态代码块实现懒汉式单例模式
 */
public class StaticCodeSingleton {
    private static final StaticCodeSingleton instance;
    private String name;

    private StaticCodeSingleton() {

    }

    static {
        instance = new StaticCodeSingleton();
    }

    public static StaticCodeSingleton getInstance() {
        return instance;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(StaticCodeSingleton.getInstance().hashCode());
        }
    }

}
